<template>

</template>

<script>
  import '@/assets/css/bootstrap.min.css'
  import '@/assets/css/swiper.min.css'
  import '@/assets/css/init.css'
  import '@/assets/css/styles.css'
  import '@/assets/css/account.css'
  import '@/assets/css/userinfo.css'
  import NavContainer from '@/components/navContainer'
  import NavOverlay from '@/components/navOverlay'
  import NavMobile from '@/components/navMobile'
  import ConsumeRecord from '@/components/consumeRecord'
  import StarRecord from '@/components/starRecord'
  import TokenTools from '@/utils/tokenTools'
  import CookieTools from '@/utils/cookieTools'
  import axios from 'axios'

    export default {
        name: "activity",
      metaInfo: {
        title: '星享俱乐部',
        titleTemplate: '%s | 星巴克',
        meta: [
          {
            name: 'keywords',
            content: ''
          },
          {
            name: 'description',
            content: '星享俱乐部'
          }
        ]
      },
      data(){
          return{
            show_menu_bol: false,
            lgMedia: window.matchMedia('(min-width: 1025px)').matches,
            curActive: 'activity',
            welcome: [
              '早上好!',
              '上午好!',
              '中午好!',
              '下午好!',
              '晚上好!'
            ],
            hello: '您好!',
            curActTab: 'consume',
            view: 'ConsumeRecord'
          }
      },
      components: {
        NavContainer: NavContainer,
        NavOverlay: NavOverlay,
        NavMobile: NavMobile,
        ConsumeRecord: ConsumeRecord,
        StarRecord: StarRecord
      },
      computed: {
        NickName(){
          return this.$store.state.NickName;
        }
      },
      mounted(){
        const _self = this;
        window.matchMedia('(min-width: 1025px)').addListener(()=>{
          _self.lgMedia = window.matchMedia('(min-width: 1025px)').matches;
        });
        this.checkLogin();
        this.trackingVisitor();
      },
      methods: {
        showMenuExec(){
          this.show_menu_bol = true;
        },
        closeMenuExec(){
          this.show_menu_bol = false;
        },
        pageRedir(item, curName){
          if(curName){
            this.curActive = curName;
          }
          this.$store.commit('pageRedir', item);
        },
        checkLogin(){
          let ReqToken = TokenTools.TokenSetting('sbux_token_cl');

          if(ReqToken){
            axios.post("users/checkLogin",{
              ReqToken: ReqToken
            }).then((res)=>{
              let data = res.data;
              if(data.status == '0'){
                let res = data.result;
                this.$store.commit('updateUserInfo', res.NickName);
                this.getHelloWord();
              }else{
                this.$store.commit('updateUserInfo', '');
              }
              CookieTools.DelCookie('sbux_token_cl');
            })
          }
        },
        getHelloWord(){
          let time = new Date(),
            hours = time.getHours(),
            index = '';

          if(hours >= 0 && hours < 8) {
            index = 0;
          }else if(hours >= 8 && hours < 12) {
            index = 1;
          }else if(hours >= 12 && hours < 14) {
            index = 2;
          }else if(hours >= 14 && hours < 20) {
            index = 3;
          }else {
            index = 4;
          }

          this.hello = this.welcome[index];
        },
        toggleActTab(tab){
          this.curActTab = tab;
          this.view = (tab === 'consume' ? 'ConsumeRecord' : 'StarRecord');
        },
        trackingVisitor() {
          let storage = window.sessionStorage || null;
          if(storage) {
            let VisitorID = storage.getItem('VisitorID'),
              page = '我的账户-消费记录';
            if(!VisitorID) return;
            axios.post('users/tracking',{
              visitorID: VisitorID,
              page: page
            })
          }
        }
      }
    }
</script>

<style scoped>

</style>
